package com.athuiju.fenxiaoback.service.impl;

import com.athuiju.fenxiaoback.entity.UmsMemberCollectSpu;
import com.athuiju.fenxiaoback.mapper.UmsMemberCollectSpuMapper;
import com.athuiju.fenxiaoback.service.UmsMemberCollectSpuService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 会员收藏的商品 服务实现类
 * </p>
 *
 * @author athuiju
 * @since 2021-07-16
 */
@Service
public class UmsMemberCollectSpuServiceImpl extends ServiceImpl<UmsMemberCollectSpuMapper, UmsMemberCollectSpu> implements UmsMemberCollectSpuService {

    @Transactional
    @Override
    public void delCollects(List<Long> spuids, String memberid) {
        for (int i=0;i<spuids.size();i++){
            QueryWrapper<UmsMemberCollectSpu> wrapper=new QueryWrapper<UmsMemberCollectSpu>();
            wrapper.eq("member_id",memberid);
            wrapper.eq("spu_id",spuids.get(i));
            boolean remove = this.remove(wrapper);
            if (!remove){
                throw  new RuntimeException();
            }
        }
    }
}
